<?php

namespace app\admin\controller;

use app\common\model\GoodsOption as GoodsOptionModel;

/**
 * 商品规格控制器
 * Class GoodsOption
 * @package app\index\controller
 */
class GoodsOption extends Base
{
    /**
     * [getIndex  添加规格]
     * @return json
     * @author [C。]
     */
    public function postAdd()
    {
        $model = new GoodsOptionModel;
        $param = input('param.');
        $user = $this->user;
        try{
            $id = $model->addData($param);
        }catch(\Exception $e){
            return admin_json(-1, '添加失败'.$e->getMessage());
        }
        writelog('添加规格--'.$id,1,$user);
        return admin_json(1,'添加成功',$id);
    }
    /**
     * [postEdit  修改规格]
     * @return json
     * @author [C。]
     */
    public function postEdit()
    {
        $model = new GoodsOptionModel;
        $param = input('param.');
        $user = $this->user;
        try{
            $id = $model->editData($param);
        }catch(\Exception $e){
            return admin_json(-1, '修改失败'.$e->getMessage());
        }
        writelog('编辑规格--'.$id,1,$user);
        return admin_json(1,'修改成功');
    }
    /**
     * [getDel  删除规格]
     * @return json
     * @author [C。]
     */
    public function getDel()
    {
        $model = new GoodsOptionModel;
        $param = input('param.');
        $user = $this->user;
        try{
            $model->editData(['id'=>$param['id'],'status'=>2]);
        }catch(\Exception $e){
            return admin_json(-1, '删除失败'.$e->getMessage());
        }
        writelog('删除规格--'.$param['id'],1,$user);
        return admin_json(1,'删除成功');
    }
}